from typing import *


class Solution:

    def findAnagrams(self, s: str, p: str) -> List[int]:
        cnt = Counter(p)
        diff = len(cnt)
        n = len(p)
        ans = []
        for i, v in enumerate(s):
            cnt[v] = cnt.get(v, 0) - 1
            if cnt[v] == 0:
                diff -= 1
            if cnt[v] == -1:
                diff += 1
            if i >= n:
                o = s[i - n]
                cnt[o] += 1
                if cnt[o] == 0:
                    diff -= 1
                if cnt[o] == 1:
                    diff += 1
            if diff == 0:
                ans.append(i - n + 1)

        return ans
